######## Taxation plots #########

library(ggplot2)
library(readxl)
library(rvest)
library(data.table)

rm(list=ls())
dev.off()

#### DATA ####
load("tax_data.RData")

#### Figure 2: Estimates of fiscal burden by province (1784) ######

pdf("neckerbarplot.pdf", height=4)

necker <- necker[order(type),]
p <-ggplot(data=necker, aes(y=percapita,x=generalite,fill=type)) +
  geom_bar(stat="identity", width = .5)+
  scale_fill_manual("legend", values = c("Consent" = "black","No consent" = "lightgray"))
p + theme_minimal() + xlab("generalite") + ylab("Per capita taxation (livres)")+
  theme(axis.text.x=element_text(angle = 90, hjust = 1, vjust=.5))

dev.off()


#### Figure E.1: Per capita tax receipts and new direct taxes (1560-1780) #######

pdf(file="taxreceiptspc_1560_1780.pdf", height=5)

receipts[YEAR>1500,c("YEAR","FRREVPC")] %>% plot(type='o', ylab="Per capita tax receipts", xlab="year")
abline(v=c(1695,1710,1749,1756,1760), lty=2)
legend("topleft",c("Creation of a new direct tax"), lty=2)

dev.off()

#### Figure E.2: Net per capita tax receipts from pays d'etat and pays d'election #######

## 17th century ##
pdf("netreceipts17.pdf", height=4)

receipts17[year<1681 & until1789==0,sum(value,na.rm=T)/sum(population,na.rm=T),keyby=year] %>% plot(ylim=c(0,7), xlim=c(1660,1695),type='o', ylab="net receipts per capita")
receipts17[until1789==0 & year>1681,sum(value,na.rm=T)/sum(population,na.rm=T),keyby=year] %>% lines(lty=1, type='o')

receipts17[year<1681 & until1789==1,sum(value,na.rm=T)/sum(population,na.rm=T),keyby=year] %>% lines(lty=2, type='o')
receipts17[year>1681 & until1789==1,sum(value,na.rm=T)/sum(population,na.rm=T),keyby=year] %>% lines(lty=2, type='o')

dev.off()

## 18th century ##

pdf(file="netreceipts18.pdf",width=6,height=6)

plot(receipts18[,c("year","noconsentpcr")], ylim=c(0,7), type='o', ylab="net receipts per capita",main="Net tax receipts per capita late 18th century")
points(receipts18[,c("year","consentpcr")], type='o', lty=2)
legend('topleft',legend=c("Pays d'election","Pays d'etat"),lty=c(1,2))

dev.off()

